package hexapawn.game;

import java.util.LinkedList;
import java.util.List;

/**
 * class TopPlayer - The Player object that starts at the bottom of the board.
 * 					 All the pieces may only move upwards. upwards is towards 
 *                   smaller rows.
 * 
 * @author ChaoSXDemon
 *
 */
public class BottomPlayer extends Player{

	public BottomPlayer(Board _board) {
		super(_board, Player.PLAYER_2);
	}
	
	protected void removeTarget(Cell target){
		Player other = board.getTopPlayer();
		other.getPieces().remove(target.getPiece());
	}

	@Override
	public List<Cell> getPossibleMoves(Cell _from){
		List<Cell> possibleMoves = new LinkedList<Cell>();
		from = _from;
		int row = from.getRow();
		int col = from.getColumn();
		if(row-1 >= 0){
			Cell above, aboveLeft, aboveRight;
			above = board.getCellAbove(from);
			if(!above.hasPiece()) possibleMoves.add(above);
			if(col-1 >= 0){
				aboveLeft = board.getCellAboveLeft(from);
				if(aboveLeft.hasPiece())
					if(aboveLeft.getPiece().getOwner() == PLAYER_1)	possibleMoves.add(aboveLeft);
			}
			if(col+1 < board.getColumn()){
				aboveRight = board.getCellAboveRight(from);
				if(aboveRight.hasPiece())
					if(aboveRight.getPiece().getOwner() == PLAYER_1) possibleMoves.add(aboveRight);
			}
		}
		if(possibleMoves.size() == 0) from = null;
		return possibleMoves;
	}
	
}
